﻿using AuthCenter.API.Application.Command.Report;
using AuthCenter.API.Application.Command.Request;
using AuthCenter.API.DTOs;
using AuthCenter.Domain.Request;
using AuthCenter.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace AuthCenter.API.Controllers
{
    /// <summary>
    /// 申请控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    public class RequestController : ControllerBase
    {
        private readonly IMediator mediator;

        public RequestController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 新增申请信息接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<APIResult<int>> CreateRequst(CreateRequestCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 获取申请信息接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIPaging<RequestModel>> GetRequest([FromQuery]GetRequestCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 修改申请信息接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<APIResult<int>> UpdateRequest(UpdateRequestCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 删除申请信息接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<int>> DelRequest([FromQuery]DelRequestCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 审批信息接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<APIResult<int>> UpdStateRequest(UpdStateRequestCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 报表接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<List<ReportDTO>>> GetReport([FromQuery]GetReportCommand request)
        {
            return mediator.Send(request);
        }
    }
}
